﻿Option Strict On
Option Explicit On
Option Infer On

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Xml.Linq
Imports GenDotNet.Task.Common
Imports GenDotNet.ObjectModel
Imports <xmlns:orm="http://kadgen.com/KADORM.xsd">
Imports <xmlns:kd="http://kadgen.com/Special.xsd">

Namespace GenInputMetadata
   Public Class SpParameterData
      Inherits BaseData
      Implements ISpParameterData

      Private mStoredProcedureData As IStoredProcedureData

      Public Shared Function Load(ByVal storedProcedureData As StoredProcedureData, ByVal element As XElement) As SpParameterData
         Dim ret = New SpParameterData(storedProcedureData.RootData, element)
         ret.mStoredProcedureData = storedProcedureData
         Return ret
      End Function

      Public Shared Function Load( _
                ByVal storedProcedureData As StoredProcedureData, _
                ByVal elements As IEnumerable(Of XElement)) _
                As List(Of ISpParameterData)
         Dim ret = New List(Of ISpParameterData)
         For Each XElement In elements
            ret.Add(Load(storedProcedureData, XElement))
         Next
         Return ret
      End Function

      Private Sub New(ByVal rootData As RootData, _
                      ByVal element As XElement)
         MyBase.New(rootData, element)
      End Sub

      Public ReadOnly Property Direction() As SpParameterDirection Implements ISpParameterData.Direction
         Get
            Return SpParameterDirectionExtensions.StringToDirection(Element.@Direction)
         End Get
      End Property

      Public ReadOnly Property Name() As String Implements ISpParameterData.Name
         Get
            Dim ret = Element.@Name
            If ret.StartsWith("@") Then
               ret = ret.Substring(1)
            End If
            Return ret
         End Get
      End Property

      Public ReadOnly Property NetType() As StandardNetType Implements ISpParameterData.NetType
         Get
            Return NetTypeExtensions.XsdToNetType(Element.@NETType)
         End Get
      End Property

      Public ReadOnly Property PropertyName() As String Implements ISpParameterData.PropertyName
         Get
            Return Element.@PropertyName
         End Get
      End Property
   End Class

End Namespace
